/**
 * 
 */
package br.com.ufrn.aipetro.ga.controller.device;

import java.util.List;

import br.com.ufrn.aipetro.ga.domain.entity.device.Critical;
import br.com.ufrn.aipetro.ga.domain.entity.device.OperationStatus;
import br.com.ufrn.aipetro.ga.domain.entity.device.Protocol;
import br.com.ufrn.aipetro.ga.domain.entity.device.controller.Controller;
import br.com.ufrn.aipetro.ga.domain.entity.mesh.Mesh;
import br.com.ufrn.aipetro.ga.domain.entity.plant.Plant;
import br.com.ufrn.aipetro.ga.domain.entity.stock.Part;
import br.com.ufrn.aipetro.ga.domain.entity.unit.Unit;
import br.com.ufrn.aipetro.ga.persist.interfaces.DaoFactory;

/**
 * @author Andre
 *
 */
public class ControllerController extends DeviceController<Controller> {
	
	DaoFactory daoFactory;
	
	public ControllerController(DaoFactory factory) {
		this.daoFactory = factory;
		setModel(new Controller());
	}
	
	public void changeAutomaticMode(Boolean automaticMode) {
		getModel().setAutomaticMode(automaticMode);
	}
	
	public void changeMv(float mv) {
		getModel().setMv(mv);
	}
	
	public void changeMvMax(float mvMax) {
		getModel().setMvMax(mvMax);
	}
	
	public void changeMvMin(float mvMin) {
		getModel().setMvMin(mvMin);
	}
	
	public void changePv(float pv) {
		getModel().setPv(pv);
	}
	
	public void changeSp(float sp) {
		getModel().setSp(sp);
	}
	
	public void changeSpMax(float spMax) {
		getModel().setSpMax(spMax);
	}
	
	public void changeSpMin(float spMin) {
		getModel().setSpMin(spMin);
	}
	
	public void persistInsert() {
		daoFactory.beginTransaction();
		daoFactory.createControllerDao().insert(getModel());
		daoFactory.commitTransaction();
	}
	
	public void persistUpdate() {
		daoFactory.beginTransaction();
		daoFactory.createControllerDao().update(getModel());
		daoFactory.commitTransaction();
	}
	
	public void persistDelete(Controller controller) {
		daoFactory.beginTransaction();
		daoFactory.createControllerDao().delete(controller);
		daoFactory.commitTransaction();
	}
	
	public List<Controller> persistSearchAll() {
		daoFactory.beginTransaction();
		List<Controller> listController = daoFactory.createControllerDao().searchAll();
		daoFactory.commitTransaction();
		return listController;
	}
	
	public List<OperationStatus> persistSearchAllOperationStatus() {
		daoFactory.beginTransaction();
		List<OperationStatus> listOperationStatus = daoFactory.createOperationStatusDao().searchAll();
		daoFactory.commitTransaction();
		return listOperationStatus;
	}
	
	public List<Critical> persistSearchAllCritical() {
		daoFactory.beginTransaction();
		List<Critical> listCritical = daoFactory.createCriticalDao().searchAll();
		daoFactory.commitTransaction();
		return listCritical;
	}
	
	public List<Protocol> persistSearchAllProtocol() {
		daoFactory.beginTransaction();
		List<Protocol> listProtocol = daoFactory.createProtocolDao().searchAll();
		daoFactory.commitTransaction();
		return listProtocol;
	}
	
	public List<Unit> persistSearchAllUnit() {
		daoFactory.beginTransaction();
		List<Unit> listUnit = daoFactory.createUnitDao().searchAll();
		daoFactory.commitTransaction();
		return listUnit;
	}
	
	public List<Plant> persistSearchPlantByUnit(Unit unit) {
		daoFactory.beginTransaction();
		List<Plant> listPlant = daoFactory.createPlantDao().searchByUnit(unit);
		daoFactory.commitTransaction();
		return listPlant;
	}
	
	public List<Mesh> persistSearchMeshByPlant(Plant plant) {
		daoFactory.beginTransaction();
		List<Mesh> listMesh = daoFactory.createMeshDao().searchByPlant(plant);
		daoFactory.commitTransaction();
		return listMesh;
	}
	
	public List<Controller> persistSearchByExample(Controller example) {
		daoFactory.beginTransaction();
		List<Controller> listController = daoFactory.createControllerDao().searchByExample(example);
		daoFactory.commitTransaction();
		return listController;
	}
	
	public List<Part> persistSearchPartByExample(Part example) {
		daoFactory.beginTransaction();
		List<Part> partList = daoFactory.createPartDao().searchByExample(example);
		daoFactory.commitTransaction();
		return partList;
	}

}
